import { createApp } from "vue";
import type { App } from "vue";
import AppComponent from "./App.vue";
import { setupRouter } from "@/router";
import { setupStore } from "@/store";
import { setupAssets, setupComponents, setupDirectives, setupMethods } from "./plugins";
import { reqConfig } from "./api/login";

const app: App = createApp(AppComponent);

const getConfig = async () => {
  try {
    const res = await reqConfig();
    sessionStorage.setItem("adminConfig", JSON.stringify(res.data));
  } catch (error) {}
};
getConfig();
function setupPlugins() {
  // 引入静态资源
  setupAssets(app);
  // 注册全局组件
  setupComponents(app);
  // 注册自定义指令
  setupDirectives(app);
  // 注册全局方法
  setupMethods(app);
}
async function setupApp() {
  // 挂载vuex状态管理
  await setupStore(app);
  // 挂载路由
  await setupRouter(app);
  app.mount("#app");
}
setupPlugins();
setupApp().then(async () => {
  console.log("vue启动成功");
  const app = document.querySelector("body>#app") as HTMLDivElement;
  if (app) {
    app.style.visibility = "visible";
  }
  const loadingMask = document.querySelector("body>.loading-mask") as HTMLDivElement;
  if (loadingMask) {
    loadingMask.style.display = "none";
  }
});
